package com.example.service.impl;

import com.example.entity.item.Items;
import com.example.entity.trace.Trace;
import com.example.entity.trace.dto.DescTraceDTO;
import com.example.mapper.UserMapper;
import com.example.mapper.dao.QRDao;
import com.example.service.QRService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;


@Service
public class QRServiceImpl implements QRService {

    @Resource
    private QRDao qrDao;

    @Resource
    private UserMapper userMapper;

    @Override
    public DescTraceDTO GetTraceDesc(String  traceUid){
        DescTraceDTO descTraceDTO=new DescTraceDTO();

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

        Trace trace= qrDao.selectTraceByUid(traceUid);
        descTraceDTO.setLastDate(sdf.format(trace.getLastDate()));
        descTraceDTO.setStartDate(sdf.format(trace.getStartDate()));

        Items item= userMapper.selectItemById(trace.getItemId());
        descTraceDTO.setTraceName(item.getItemName());
        descTraceDTO.setTraceOrigin(item.getItemAddress());

        descTraceDTO.setTimeLine(qrDao.selectTraceLineByUid(traceUid));

        return descTraceDTO;
    }
}
